<?php
// +----------------------------------------------------------------------
// | Author: ZYN Fl
// +----------------------------------------------------------------------
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Db;
class Cate extends Common
{
    public function index()
    {
    	$cate=Db::name('category')->select();
		
		ifExist($cate);
        $this->assign("cate",$cate);
        $this->assign('a','Cate');
        return $this->fetch();
    }
     public function addcate(){
        $this->assign('a','Cate');
        return $this->fetch();
    }
    public function addxinxi(){
        $cname = input('cname');
        $data = array(
            'cname' => $cname
            );
        $category=Db::name('category')->insert($data);
        if($category){
            return 1;
        }
    }
    //编辑信息
    public function update()
    {
        $cid = input('cid');
        $data=Db::name('category')->where("cid='$cid'")->find();
        $this->assign("data",$data);
        $this->assign('a','Cate');
        return $this->fetch();
    }
    //保存信息
    public function xiugai(){
        $cid = input('cid');
        $cname = input('cname');
        $data = array(
            'cid' => $cid,
            'cname' => $cname
            );
        $cate =Db::name('category')->where("cid='$cid'")->update($data);
        if($cate!==false){
			
			return 1;
		  
        }
    }
    //删除
    public function del(){
        $cid = input('cid');
        $data = array(
            'cid' =>$cid
            );
        $del=Db::name('category')->where("cid='$cid'")->delete($data);
        if($del){
            return 1;
        }
    }
}